//      main.c
//
//      Copyright 2011 richard <richard@desktop>
//
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.rt65r45653	\c v
#include "common.h"

void delay_ms(u16 ms)
{
	while(ms--)
	{
		_delay_ms(1);
	}
}

void AllOff()
{
	//Turn off the lcd display by writing 0 to all cells.
	PORTD |= 1<<PD5;
	PORTA = 255;
	PORTD &= ~(1<<PD5);

	PORTD |= 1<<PD4;
	PORTA = 0;
	PORTD &= ~(1<<PD4);


	_delay_ms(1);

	//Turn off the 1602 display.

	PORTF &= ~ (1 <<1);
	PORTF &= ~ (1 <<2);
	PORTF |= (1 <<3);
	PORTA = 0x38;// display mode settings
	delay_ms(1);
	PORTF &= ~ (1 <<3) ;

	delay_ms (1);
	PORTF &= ~ (1 <<1);
	PORTF &= ~ (1 <<2);
	PORTF |= (1 <<3);
	PORTA = 0x08;// display off
	delay_ms(1);
	PORTF &= ~ (1 <<3) ;

	delay_ms (1);


	//I try to leave pins in pull up mode to save power. See page 70 on the data sheet.
	//But that is not ideal. The LCD display needs to be set to input to keep writes to the 1602 if on from showing up.
	PORTA = 255;
	PORTB = 255;
	PORTC = 255;
	PORTD = ~(1<<PD5);
	PORTE = 255;
	PORTF = 255;
	PORTG = 255;

	_delay_ms(1);

	DDRA = 255;
	DDRB = 255;
	DDRC = 255;
	DDRD = 255;
	DDRE = 255;
	DDRF = 255;
	DDRG = 255;

	_delay_ms(1);



}
